package com.library.control.find;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.library.model.dto.register.FindIdDTO;
import com.library.model.service.IdFindService;

public class IdFindController extends AbstractFormController{

	private IdFindService idfindservice;
	
	public void setIdfindservice(IdFindService idfindservice) {
		this.idfindservice = idfindservice;
	}

	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String name=request.getParameter("name");
		String jumin=request.getParameter("jumin1")+"-"+request.getParameter("jumin2");
		FindIdDTO dto=new FindIdDTO(name, jumin);
		return dto;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, BindException arg3)
			throws Exception {
		ModelAndView mav=new ModelAndView();
		FindIdDTO dto=idfindservice.findId((FindIdDTO)arg2);
		mav.addObject("dto",dto);
		mav.setViewName("findidok");
		return mav;
	}



	@Override
	protected ModelAndView showForm(HttpServletRequest arg0,
			HttpServletResponse arg1, BindException arg2) throws Exception {
		return new ModelAndView("idfindform");
	}




}
